package firstServlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gozap.model.User;

public class Login extends HttpServlet {

	private static final long serialVersionUID = 1L;

	private User user;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// Cookie[] cookies = req.getCookies();
		// for (Cookie cookie : cookies) {
		// System.out.println("============");
		// System.out.println(cookie.getDomain());
		// System.out.println(cookie.getName());
		// System.out.println(cookie.getValue());
		// System.out.println(cookie.getPath());
		// System.out.println("============");
		// }
		// System.out.println(user);
		// String uuid = UUID.randomUUID().toString().replaceAll("-", "");
		// Cookie cookie = new Cookie("bizxing", uuid);
		// resp.addCookie(cookie);
		//
		// String[] arr = { "one", "two", "three" };
		// req.setAttribute("arr", arr);
		// req.setAttribute("one", "1");
		//
		// String jsp = "/welcome.jsp";
		// String password = req.getParameter("password");
		// if (!"1".equals(password)) {
		// jsp = "/login.jsp";
		// } else {
		// req.getSession().setAttribute("p", password);
		// }
		//
		// req.getRequestDispatcher(jsp).forward(req, resp);

		response.setContentType("text/html");
		response.setStatus(HttpServletResponse.SC_OK);
		response.getWriter().println("<h1>Hello Servlet</h1>");
		response.getWriter().println("session=" + request.getSession(true).getId());
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doGet(req, resp);
	}

	public void tt(HttpServletRequest req, HttpServletResponse resp) {
		String temp;
		temp = req.getContextPath();
		System.out.println("getContextPath " + temp);
		temp = req.getLocalAddr();
		System.out.println("getLocalAddr " + temp);
		temp = req.getLocalName();
		System.out.println("getLocalName " + temp);
		temp = req.getPathInfo();
		System.out.println("getPathInfo " + temp);
		temp = req.getPathTranslated();
		System.out.println("getPathTranslated " + temp);
		temp = req.getRequestURI();
		System.out.println("getRequestURI " + temp);
		temp = req.getRequestURL().toString();
		System.out.println("getRequestURI " + temp);
		temp = req.getServletPath();
		System.out.println("getServletPath " + temp);
		int tempInteger = req.getRemotePort();
		System.out.println("getRemotePort " + tempInteger);

	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

}
